package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link EnumerationLiteral} creation command
 * @author Remi Schnekenburger
 */
public class EnumerationLiteralCreateCommandTest extends PapyrusCommandTest {

	private Enumeration enumeration;

	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public EnumerationLiteralCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Enumeration.class,model);
		stack.execute(papyrusCommand);
		// Class_0 is created!
		enumeration=(Enumeration)model.getPackagedElement("Enumeration_0");

		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.EnumerationLiteral.class, enumeration);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		// execute command
		stack.execute(papyrusCommand);
		Element clazz=enumeration.getOwnedLiteral("Literal_0");
		assertNotNull("the enumeration literal is created",clazz);
		assertTrue("this is not a enumeration literal",((clazz)instanceof EnumerationLiteral));

		// undo command
		stack.undo();
		assertNull("the enumeration literal exist!", enumeration.getOwnedLiteral("Literal_0"));

		// redo command
		stack.redo();
		clazz=enumeration.getOwnedLiteral("Literal_0");
		assertNotNull("the enumeration literal is re-added to enumeration",clazz);
		assertTrue("this is not a enumeration literal",((clazz)instanceof EnumerationLiteral));

	}

}
